#define _CRT_SECURE_NO_WARNINGS 1


#include<iostream>

using namespace std;

bool Func(int n)
{
	while (n)
	{
		if (n % 10 == 2 || n % 10 == 0 || n % 10 == 1 || n % 10 == 9)
		{
			return true;
		}

		n /= 10;
	}

	return false;
}

int main()
{
	int n = 0;
	cin >> n;

	int sum = 0;
	for (int i = 1; i <= n; i++)
	{
		if (Func(i))
		{
			sum += i;
		}
	}

	cout << sum << endl;

	return 0;
}